package com.example.ujsfish.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class MyDatabaseHelper extends SQLiteOpenHelper {

    /**
     * @param context 上下文
     * @  数据库名称
     * @  游标工场
     * @  版本号
     */
    public MyDatabaseHelper(@Nullable Context context) {
        super(context, Constants.DATABASE_MANE, null, Constants.VERSION_CODE);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        //第一次创建时回调
        String sql = "create table " + Constants.TABLE_NAME + "(pool_id text, path_order integer,point_start text,point_end text,ship_id text)";
        db.execSQL(sql);
        System.out.println("database has be created");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        String sql;
        //升级数据库是回调
        switch (oldVersion){
            case 1:
                //添加字段
                sql = "alter table " + Constants.TABLE_NAME + " add column speed integer";
                db.execSQL(sql);
                break;

        }
    }
}
